package main

import (
	"flag"
	"time"
)

type cmdParams struct {
	logFilePath string
	routineNum int
}

type digData struct {
	time   string
	url    string
	refer  string
	ua     string
}

type urlData struct {
	data   digData
	uid    string
}



func main()  {

	//获取参数
	//文件地址
	logFilePath := flag.String("logFilePath","D:/goweb/src/test/run/web.log","log file path:")
	//并发度
	routineNum := flag.Int("routineNum",5,"routine num:")
	//打日志目标
	l := flag.String("l","C:/temp/log","this programe runtime log target file path")
	flag.Parse() //解析

	params := cmdParams{ *logFilePath,*routineNum}


	//初始化一些 channel ,用于数据传递
	var logChannel = make(chan string, 3*routineNum)
	var pvChannel = make(chan urlData, *routineNum)
	var uvChannel = make(chan urlData, *routineNum)
	var storageChannel = make(chan storageBlock, *routineNum)

	//日志消费者
	go readFileLine(params,logFilePath)

	//创建一组日志处理
	for i:=0; i<params.routineNum; i++ {
		go logconsumer(logChannel, pvChannel, uvChannel)
	}

	//创建 pv,uv统计器
	go pvCounter(pvChannel, storageChannel )
	go uvCounter(uvChannel, storageChannel )


	//创建存储器
	go dataStorage(storageChannel)

	time.Sleep(1000*time.Second) //保证主程序不退出，协程可以继续运行

}

func dataStorage(storageChannel chan  storageBlock)  {

}

func pvCounter(pvChannel chan urlData, storageChannel chan storageBlock)  {

}
func uvCounter(pvChannel chan urlData, storageChannel chan storageBlock)  {

}

func logconsumer(logChannel chan string , pvChannel , uvChannel chan urlData)  {

}

func readFileLine(params cmdParams,logChanner chan string)  {
	
}